<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    template="layout/template.xhtml">

<ui:define name="body">

    <h:form id="customer" styleClass="edit">

        <rich:panel>
            <f:facet name="header">#{customerHome.managed ? 'Edit' : 'Add'} Customer</f:facet>





            <s:decorate id="nameField" template="layout/edit.xhtml">
                <ui:define name="label">Name</ui:define>
                <h:inputText id="name"
                           size="20"
                      maxlength="20"
                          value="#{customerHome.instance.name}">
                    <a:support event="onblur" reRender="nameField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <s:decorate id="phoneField" template="layout/edit.xhtml">
                <ui:define name="label">Phone</ui:define>
                <h:inputText id="phone"
                           size="20"
                      maxlength="20"
                          value="#{customerHome.instance.phone}">
                    <a:support event="onblur" reRender="phoneField" bypassUpdates="true" ajaxSingle="true"/>
                </h:inputText>
            </s:decorate>


            <div style="clear:both">
                <span class="required">*</span>
                required fields
            </div>

        </rich:panel>

        <div class="actionButtons">

            <h:commandButton id="save"
                          value="Save"
                         action="#{customerHome.persist}"
                       disabled="#{!customerHome.wired}"
                       rendered="#{!customerHome.managed}"/>

            <h:commandButton id="update"
                          value="Save"
                         action="#{customerHome.update}"
                       rendered="#{customerHome.managed}"/>

            <h:commandButton id="delete"
                          value="Delete"
                         action="#{customerHome.remove}"
                      immediate="true"
                       rendered="#{customerHome.managed}"/>

            <s:button id="cancelEdit"
                   value="Cancel"
             propagation="end"
                    view="/Customer.xhtml"
                rendered="#{customerHome.managed}"/>

            <s:button id="cancelAdd"
                   value="Cancel"
             propagation="end"
                    view="/#{empty customerFrom ? 'CustomerList' : customerFrom}.xhtml"
                rendered="#{!customerHome.managed}"/>

        </div>
    </h:form>

<rich:tabPanel switchType="ajax">

    <rich:tab label="Address">
    <div class="association" id="addressParent">

        <h:outputText value="There is no address associated with this customer."
                   rendered="#{customerHome.instance.address == null}"/>

        <rich:dataTable var="_address"
                   value="#{customerHome.instance.address}"
                rendered="#{customerHome.instance.address != null}"
              rowClasses="rvgRowOne,rvgRowTwo"
                      id="addressTable">
            <h:column>
                <f:facet name="header">Id</f:facet>
                <h:outputText value="#{_address.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">City</f:facet>
                <h:outputText value="#{_address.city}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Country</f:facet>
                <h:outputText value="#{_address.country}"/>
            </h:column>
            <h:column>
                <f:facet name="header">State</f:facet>
                <h:outputText value="#{_address.state}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Street</f:facet>
                <h:outputText value="#{_address.street}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Zipcode</f:facet>
                <h:outputText value="#{_address.zipcode}"/>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            <s:button id="#{customerHome.instance.address != null ? 'changeParent' : 'selectParent'}" value="#{customerHome.instance.address != null ? 'Change' : 'Select'} address"
                       view="/AddressList.xhtml">
                <f:param name="from" value="CustomerEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>

    <rich:tab label="Company">
    <div class="association" id="companyParent">

        <h:outputText value="There is no company associated with this customer."
                   rendered="#{customerHome.instance.company == null}"/>

        <rich:dataTable var="_company"
                   value="#{customerHome.instance.company}"
                rendered="#{customerHome.instance.company != null}"
              rowClasses="rvgRowOne,rvgRowTwo"
                      id="companyTable">
            <h:column>
                <f:facet name="header">Id</f:facet>
                <h:outputText value="#{_company.id}"/>
            </h:column>
            <h:column>
                <f:facet name="header">Name</f:facet>
                <h:outputText value="#{_company.name}"/>
            </h:column>
        </rich:dataTable>

        <div class="actionButtons">
            <s:button id="#{customerHome.instance.company != null ? 'changeParent' : 'selectParent'}" value="#{customerHome.instance.company != null ? 'Change' : 'Select'} company"
                       view="/CompanyList.xhtml">
                <f:param name="from" value="CustomerEdit"/>
            </s:button>
        </div>

    </div>
    </rich:tab>
</rich:tabPanel>
</ui:define>

</ui:composition>
